package com.ssy.lingxi.product.entity.platform;

import com.fasterxml.jackson.annotation.JsonManagedReference;
import lombok.Getter;
import lombok.Setter;

import javax.persistence.*;
import java.io.Serializable;
import java.util.List;

/**
 * 品类实体类--平台后台
 * @author jw.chen
 * @version 2.0.0
 * @date 2020/6/22
 */
@Getter
@Setter
@Entity
@Table(schema = "public", name = "product_category", indexes = {@Index(name = "product_category_name_idx", columnList = "name"),
        @Index(name = "product_category_type_idx", columnList = "type"),
        @Index(name = "product_category_level_idx", columnList = "level"),
        @Index(name = "product_category_parent_id_idx", columnList = "parentId"),
        @Index(name = "product_category_sort_idx", columnList = "sort")})
public class Category implements Serializable {
    private static final long serialVersionUID = 8657720611585598488L;
    /**
     * 主键id
     */
    @Id
    @GeneratedValue(strategy= GenerationType.SEQUENCE, generator="category_seq")
    @SequenceGenerator(sequenceName="product_category_seq", name="category_seq",allocationSize = 1)
    private Long id;

    /**
     * 品类名称
     */
    @Column(columnDefinition = "varchar(16)", nullable = false)
    private String name;

    /**
     * 品类类型：1-实物商品、2-虚拟商品、3-服务商品、4-积分兑换商品
     */
    @Column(columnDefinition = "int", nullable = false)
    private Integer type;

    /**
     * 品类图片url路径
     */
    @Column(columnDefinition = "varchar(250)")
    private String imageUrl;

    /**
     * 级别
     */
    @Column(columnDefinition = "int", nullable = false)
    private Integer level;

    /**
     * 品类父id
     */
    @Column(columnDefinition = "int8", nullable = false)
    private Long parentId;

    /**
     * 完整Id
     */
    @Column(columnDefinition = "varchar(100)", nullable = false)
    private String fullId;

    /**
     * 排序
     */
    @Column(columnDefinition = "int")
    private Integer sort;

    /**
     * 创建时间
     */
    @Column(columnDefinition = "int8", nullable = false)
    private Long createTime = System.currentTimeMillis();

    /**
     * 品类对应的属性列表
     */
    @JsonManagedReference
    @ManyToMany(cascade=CascadeType.PERSIST,fetch=FetchType.EAGER)
    @JoinTable(name="product_category_attribute",
            joinColumns={ @JoinColumn(name="category_id", referencedColumnName="id")},
            inverseJoinColumns={@JoinColumn(name="attribute_id", referencedColumnName="id")})
    private List<Attribute> attributeList;
}
